﻿using System;
using System.Runtime.InteropServices;

namespace Milan.Windows
{
	public class kernel32
	{
		public const int FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x100;
		public const int FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x2000;
		public const int FORMAT_MESSAGE_FROM_HMODULE = 0x800;
		public const int FORMAT_MESSAGE_FROM_STRING = 0x400;
		public const int FORMAT_MESSAGE_FROM_SYSTEM = 0x1000;
		public const int FORMAT_MESSAGE_IGNORE_INSERTS = 0x200;
		public const int FORMAT_MESSAGE_MAX_WIDTH_MASK = 0xFF;
		[DllImport("kernel32")]
		public extern static int FormatMessage( int dwFlags, IntPtr lpSource, int dwMessageId, int dwLanguageId,
			string lpBuffer, uint nSize, int argumentsLong);

		[DllImport("kernel32", EntryPoint = "GetCurrentProcess", ExactSpelling = true)]
		public static extern IntPtr GetCurrentProcess();

		[DllImport("kernel32", EntryPoint = "GetCurrentProcessId", ExactSpelling = true)]
		public static extern uint GetCurrentProcessId();

		[DllImport("kernel32", EntryPoint = "GetCurrentThreadId", ExactSpelling = true)]
		public static extern uint GetCurrentThreadId();

		[DllImport("kernel32")]
		public extern static int GetLastError();
      
		public delegate int UnhandledExceptionFilter(IntPtr lpTopLevelExceptionFilter);
		[DllImport("Kernel32")]
		public static extern IntPtr SetUnhandledExceptionFilter(UnhandledExceptionFilter filter);

		[DllImport("Kernel32")]
		public static extern IntPtr GetExceptionInformation();

		[StructLayoutAttribute(LayoutKind.Sequential, Pack = 4, Size = 0)]
		public struct FILETIME
		{
			public uint dwLowDateTime;
			public uint dwHighDateTime;
		}

		[StructLayoutAttribute(LayoutKind.Sequential, Pack = 4, Size = 0, CharSet = CharSet.Unicode)]
		public struct WIN32_FIND_DATA
		{
			public uint dwFileAttributes;
			public FILETIME ftCreationTime;
			public FILETIME ftLastAccessTime;
			public FILETIME ftLastWriteTime;
			public uint nFileSizeHigh;
			public uint nFileSizeLow;
			public uint dwReserved0;
			public uint dwReserved1;
			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] // MAX_PATH
			public string cFileName;
			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
			public string cAlternateFileName;
		}
	}
}
